import java.util.LinkedList;
import java.util.Queue;

import javax.swing.tree.TreeNode;

public class lk111 {
    public static void main(String[] args) {
        
    }
    public int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        int depth=1;
        while(!q.isEmpty()){
            int sz=q.size();
            for(int i=0;i<sz;i++){
                TreeNode cur = q.poll();
                if(cur.left==null&&cur.right==null){
                    return depth;
                }
                if(cur.left!=null){
                    q.offer(cur.left);
                }
                if(cur.left!=null){
                    q.offer(cur.left);
                }
            }
            depth++;
        }
        return depth;
    }
}
